/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * This file is part of JMail                                              *
 * Copyright (C) 2002-2003 Yvan Norsa <norsay@wanadoo.fr>                  *
 *                                                                         *
 * JMail is free software; you can redistribute it and/or modify           *
 * it under the terms of the GNU General Public License as published by    *
 * the Free Software Foundation; either version 2 of the License, or       *
 * any later version.                                                      *
 *                                                                         *
 * JMail is distributed in the hope that it will be useful,                *
 * but WITHOUT ANY WARRANTY; without even the implied warranty of          *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *
 * GNU General Public License for more details.                            *
 *                                                                         *
 * You should have received a copy of the GNU General Public License along *
 * with JMail; if not, write to the Free Software Foundation, Inc.,        *
 * 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                 *
 *                                                                         *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

import java.awt.event.*;
import javax.swing.*;

/** This class displays a little dialog asking for a password */
class AskPasswordDialog extends JDialog
{
    JPanel panel;
    
    JPasswordField passwordField;
    JButton okButton;

    AskPasswordDialogListener listener;

    
    
    /** Password entered */
    String password;

    /** Constructor
     *  @param title dialog title
     */
    AskPasswordDialog(String title)
    {
	super((JFrame)null, title, true);

	panel = new JPanel();

	listener = new AskPasswordDialogListener();

	passwordField = new JPasswordField(20);
	panel.add(passwordField);

	okButton = new JButton("OK");
	okButton.addActionListener(listener);
	panel.add(okButton);

	setContentPane(panel);

	pack();
	setVisible(true);
    }

    /* Returns the password entered
     *  @return password entered by the user
     */
    String getPassword()
    {
	return(password);
    }

    /** Listener for this class */
    class AskPasswordDialogListener implements ActionListener
    {
	/** This method is invoked when an event is triggered
	 *  @param e event
	 */
	public void actionPerformed(ActionEvent e)
	{
	    char[] pass = passwordField.getPassword();
	    password = String.valueOf(pass).trim();

	    if(password.compareTo("") != 0)
		hide();
	}
    }
}
